package com.devin.dao;

import com.devin.pojo.Permission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PermissionMapper {

    @Select(" select * from permission where id in(select permissionId from role_permission where roleId=#{roleId})")
    List<Permission> getPermissionsById(Integer roleId);

    @Select(" select * from permission ")
    List<Permission> getPermissions();

    @Insert(" insert into permission values(null,#{permissionName,jdbcType=VARCHAR},#{url,jdbcType=VARCHAR})")
    void addPermission(Permission permission);

    @Update((" delete from role_permission where permissionId=#{permissionId}"))
    void delRoleAndPermission(Integer permissionId);

    @Update(" delete from permission where id=#{permissionId}")
    void delPermission(Integer permissionId);

    @Select(" select * from permission where id not in(select permissionId from role_permission where roleId=#{roleId})")
    List<Permission> getPermissions2Json(Integer roleId);
}
